package Dao.DaoImpl;

import Dao.OutApplyDao;
import Utils.JDBCUtils;
import domain.OutApply;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class OutApplyDaoImpl implements OutApplyDao {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
    @Override
    public List<OutApply> outApplyList() {
        String sql ="select * from outapply";

        return template.query(sql,new BeanPropertyRowMapper<>(OutApply.class));
    }

    @Override
    public void updateApplyStateById(int id, String state,String checkPeo) {
        String sql ="update outapply set checkstate=?,checkPeo=? where id=?";
        template.update(sql,state,checkPeo,id);
    }

    @Override
    public List<OutApply> noCheckApplyList() {
        String sql = "select * from outapply where checkstate='false' ";
        return template.query(sql,new BeanPropertyRowMapper<>(OutApply.class));

    }

    @Override
    public void addApply(OutApply app) {
        System.out.println(app);
        String sql ="insert into outapply values(null,?,?,?,?,?,null)";
        template.update(sql,app.getStunum(),app.getName(),app.getOutReason(),app.getLeftTime(),app.getCheckstate());

    }

    @Override
    public OutApply selectOutApplyById(int id) {
        String sql ="select * from outapply where id=?";
        return template.queryForObject(sql,new BeanPropertyRowMapper<>(OutApply.class),id);
    }

}
